package com.isoft.demo01.service.impl;

import com.isoft.demo01.dao.GameDao;
import com.isoft.demo01.dao.impl.GameRepository;
import com.isoft.demo01.entity.Game;

import com.isoft.demo01.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GameImplService  {
    @Autowired
    GameRepository gameRepository;
    @Autowired
    GameDao gameDao;

    public Map<String,Object> gamepage(Integer gameid, String gamename, Integer page, Integer size) {
        if (null !=gameid&&gameid<1 ){
            gameid=null;
        }
        if (StringUtil.isEmpty(gamename)){
            gamename=null;
        }
        if (null== page||page<1){
            page=1;
        }
        if (null==size||size<1){
            size=10;
        }
        List<Game> games=gameDao.findLimit(gameid,gamename, (page-1)*size, size);
        int count=gameDao.getCount(gameid, gamename);
        Map<String,Object> map= new HashMap<>();
        map.put("count",count);
        map.put("data",games);
        return map;
    }

    public boolean add(Game game) {
        if (null==game){
            return false;
        }if (StringUtil.isEmpty(game.getGamename())){
            return false;
        }
       return gameRepository.insert(game)>0;
    }
    public  List<Game> findmenu(Integer typeid){
        return gameDao.findmenu(typeid);
    }
}
